package com.zhuiyun.project.api.reservation.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zhuiyun.project.annotation.OptLog;
import com.zhuiyun.project.api.course.entity.Course;
import com.zhuiyun.project.api.course.mapper.CourseMapper;
import com.zhuiyun.project.api.course.service.ICourseService;
import com.zhuiyun.project.api.memberUserManagement.entity.MemberUserManagement;
import com.zhuiyun.project.api.memberUserManagement.mapper.MemberUserManagementMapper;
import com.zhuiyun.project.api.reservation.entity.Reservation;
import com.zhuiyun.project.api.reservation.service.IReservationService;
import com.zhuiyun.project.api.vipPlan.entity.MemberPlan;
import com.zhuiyun.project.api.vipPlan.mapper.VipPlanMapper;
import com.zhuiyun.project.common.response.CommonResult;
import com.zhuiyun.project.utils.constants.CommonConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * @ClassName ReservationController
 * @Description TODO
 * @Author xy
 * @Date 2023/11/19 19:41
 **/
@RestController
@Api(tags = "预约管理")
@RequestMapping("/reservation")
@Slf4j
public class ReservationController {

    @Resource
    private MemberUserManagementMapper memberUserManagementMapper;

    @Resource
    private IReservationService reservationService;

    @Resource
    private VipPlanMapper vipPlanMapper;

    @Resource
    private ICourseService courseService;

    /*
    * @Author xy
    * @Description todo 申请预约
    * @Date 2023/11/20 15:11
    * @Return
    * @param
    */
    @PostMapping("/add")
    @ApiOperation(value = "申请预约")
    @OptLog(modular = "预约管理", type = CommonConstants.ADD, describe = "添加")
    public CommonResult addReservation(@RequestParam String id,
                                       @RequestParam String latestSelectedDate,
                                       @RequestParam Integer courseId,
                                       @RequestParam Integer Id,
                                       @RequestParam String selectedTimeId,
                                       Reservation reservation){
        // 获取当前时间
        Date datetime = new Date();
        reservation.setCreateTime(datetime);
        reservation.setUpdateTime(datetime);
        reservation.setStudentId(Integer.parseInt(id));
        reservation.setReservationStatus("1");
        reservation.setCourseTime("1");

        reservation.setCourseId(courseId);
        reservation.setCoachId(Id);
        reservation.setCourseTime(selectedTimeId);
        // 分割日期格式
        String resultString = latestSelectedDate.replace('/', '-');
        reservation.setReservationTime(resultString);

        reservationService.updateById(reservation);
        return CommonResult.ok("申请成功");
    }

}
